package com.moter.bigdata.task;

import com.moter.bigdata.entity.JobInfo;
import com.moter.bigdata.service.JobInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;


@Component
public class JobInfoPipeline implements Pipeline {
    @Autowired
    private JobInfoService jobInfoService;

    @Override
    public void process(ResultItems resultItems, Task task) {
        //获取封装号的招聘详情对象
        JobInfo jobInfo = resultItems.get("jobInfo");
        //判断数据是否为空
        if (jobInfo != null) {
            //持久化到数据库
            jobInfoService.save(jobInfo);
            System.out.println("添加成功: "+jobInfo.getJobName());
        }
    }
}
